<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>05-js对象和JSON的转换</title>
</head>
<body>
<script>
  var stu={
      name:"zyh",
      age:18,
      address:"武汉",
      show:function () {
          console.log(this.name+"--"+this.age+"--"+this.address);
      }
  };
  // js 对象转 JSON
  var stuJson = JSON.stringify(stu);
  console.log(stuJson);//{"name":"zyh","age":18,"address":"武汉"}

  // JSON 字符串转 js 对象
  var str="{\"name\":\"dz\",\"age\":18,\"address\":\"理塘\"}";
  var parse = JSON.parse(str);
  console.log(parse);

  // eval() JSON 字符串转为 js 对象
  var eval1 = eval({"name":"cxk","age":18,"otherName":"才艾虚可瘟"});
  console.log(eval1);
</script>
</body>
</html>